package com.example.tests;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

import java.util.Set;

import org.testng.annotations.Test;

public class ContactCreationTests extends TestBase {
	
	@Test(dataProvider = "randomContacts")
	public void testContactCreation(ContactObject validContact, int contactNumber) throws Exception {
		Set<ContactObject> oldList = app.getContactHelper().getContacts();
		app.getContactHelper().createContact(validContact);
		Set<ContactObject> newList = app.getContactHelper().getContacts();
		//assertThat(newLIst, equalsTo (oldList.withAdded(validContact)));
		verifyContactAdded(oldList, validContact, newList);
	}

	private void verifyContactAdded(Set<ContactObject> oldList,
			ContactObject validContact, Set<ContactObject> newList) {
		// TODO Auto-generated method stub
		    assertThat(newList.size(), equalTo(oldList.size()+1));
			validContact.setFullName(validContact.getFirstName() + " " + validContact.getLastName());
			validContact.setId("$$$");
		 	oldList.add(validContact);
		 	validContact.setId(null);
			assertThat(newList, equalTo(oldList));
	}


	@Test
	public void test2EmptyDataContactCreation() throws Exception {
		ContactObject emtyDataContact = new ContactObject()
		.setId(null).setFirstName("")
		.setLastName("")
		.setMainAddress("")
		.setHomeTel("")
		.setMobileTel("")
		.setOtherPhone("")
		.setMainMail("")
		.setOtherMail("")
		.setNewGroup(null)
		.setBirthDay(null)
		.setBirthMonth(null)
		.setBirthYear(null)
		.setOtherAddress("")
		.setOtherPhone("");
		app.getContactHelper().createContact(emtyDataContact);
	}
}
